using System;
using System.Collections.Generic;
using Slqj.Common;
using Shc.Sql;
namespace Slqj.Data
{	
	[Serializable]
	public class XYZ2SystemConfig
		: BaseXYZ2SystemConfig
	{	
		#region 通用操作
		/// <summary>
        /// 新增数据
        /// </summary>
        /// <returns></returns>
		public bool Insert()
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {

                return DbManager.Current.Insert(ss, this);
            }
        }
		
		/// <summary>
        /// 新增数据,使用事务
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <returns></returns>
		public bool Insert(DbSession ss)
        {
            return DbManager.Current.Insert(ss, this);
        }
		
		/// <summary>
        /// 更新实体
        /// </summary>
        /// <returns></returns>
        public bool Update()
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {

                return DbManager.Current.Update(ss, this);
            }
        }
		
		/// <summary>
        /// 更新实体,使用事务
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <returns></returns>
		public bool Update(DbSession ss)
        { 
			return DbManager.Current.Update(ss, this);          
        }
		
		/// <summary>
        /// 删除实体
        /// </summary>
		/// <param name="criteria"></param>
        /// <returns></returns>
        public bool Delete()
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.Delete(ss, this);
            }
        }
		
		/// <summary>
        /// 删除实体,使用事务
        /// </summary>
        /// <param name="ss">数据库session</param>
        /// <returns></returns>
		public bool Delete(DbSession ss)
        {
           return DbManager.Current.Delete(ss, this);            
        }
		
		/// <summary>
        /// 根据条件批量删除
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static bool Delete(Criterion[] criteria)
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.DeleteEntities(ss,TableXYZ2SystemConfig.Table,criteria);
            }
        }

        /// <summary>
        /// 根据条件使用事务批量删除
        /// </summary>
		/// <param name="ss">数据库session</param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static bool Delete(DbSession ss,Criterion[] criteria)
        {
           return DbManager.Current.DeleteEntities(ss, TableXYZ2SystemConfig.Table, criteria);
        }
		
		/// <summary>
        /// 根据条件查询单个实体
        /// </summary>
        /// <returns></returns>
        public static XYZ2SystemConfig Find(params Criterion[] criteria)
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.Find<XYZ2SystemConfig>(ss,criteria);
            }
        }
		
		/// <summary>
        /// 根据条件查询单个实体
        /// </summary>
        /// <returns></returns>
        public static XYZ2SystemConfig Find(DbSession ss,params Criterion[] criteria)
        {
            return DbManager.Current.Find<XYZ2SystemConfig>(ss,criteria);
        }

		/// <summary>
        /// 根据主键查询实体
        /// </summary>
		/// <param name="keys"></param>
        /// <returns></returns>
        public static XYZ2SystemConfig FindByPK(params object[] keys)
        {
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                return DbManager.Current.FindPK<XYZ2SystemConfig>(ss, keys);
            }
        }
		
		/// <summary>
        /// 根据主键查询实体
        /// </summary>
		/// <param name="keys"></param>
        /// <returns></returns>
        public static XYZ2SystemConfig FindByPK(DbSession ss,params object[] keys)
        {
            return DbManager.Current.FindPK<XYZ2SystemConfig>(ss, keys);
        }
		
		/// <summary>
        /// 根据条件查询
        /// </summary>
		/// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindAll(Order[] orders, params Criterion[] criteria)
        {
            IList<XYZ2SystemConfig> list=new List<XYZ2SystemConfig>();
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                DbManager.Current.Query(ss, list, orders, criteria);
                return list;
            }
        }
		
		/// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindAll(params Criterion[] criteria)
        {
			return FindAll(new Order[0],criteria);
		}
		
		/// <summary>
        /// 根据条件查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindAll(DbSession ss,params Criterion[] criteria)
        {
			return FindAll(new Order[0],ss,criteria);
		}
		
		/// <summary>
        /// 根据条件查询
        /// </summary>
		/// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindAll(Order[] orders, DbSession ss,params Criterion[] criteria )
        {
            IList<XYZ2SystemConfig> list=new List<XYZ2SystemConfig>();
            
            DbManager.Current.Query(ss, list, orders, criteria);
            return list;            
        }
		
		/// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindByPage(int curPage,int pagesize,Order[] orders, 
			params Criterion[] criteria)
        {
            IList<XYZ2SystemConfig> list = new List<XYZ2SystemConfig>();
            using (DbSession ss = DbManager.Current.OpenSession())
            {
                DbManager.Current.Query(ss,list, curPage, pagesize, orders, criteria);
                return list;
            }
        }
		
		/// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindByPage(int curPage,int pagesize,params Criterion[] criteria)
        {
			return FindByPage(curPage,pagesize,new Order[0],criteria);
		}
		
		/// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindByPage(int curPage,int pagesize,
			DbSession ss,params Criterion[] criteria)
        {
			return FindByPage(curPage,pagesize,new Order[0],ss,criteria);
		}
		
		/// <summary>
        /// 根据条件分页查询
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public static IList<XYZ2SystemConfig> FindByPage(int curPage,int pagesize,Order[] orders, 
			DbSession ss,params Criterion[] criteria)
        {
            IList<XYZ2SystemConfig> list = new List<XYZ2SystemConfig>();
            
            DbManager.Current.Query(ss,list, curPage, pagesize, orders, criteria);
            return list;
        }
		#endregion 

        /// <summary>
        /// 
        /// </summary>
        /// <param name="configs"></param>
        /// <returns></returns>
        public static bool SaveMulti(XYZ2SystemConfig[] configs)
        {
            bool result = false;
            if (configs.Length > 0)
            {
                using (DbTransCounter trans = new DbTransCounter(DbManager.Current.OpenSession(), true).BeginTransaction())
                {
                    foreach (XYZ2SystemConfig systemConfig in configs)
                    {
                        systemConfig.Update(trans.Session);
                    }

                    trans.Commit();
                    result = true;
                }
            }
            else
            {
                result = true;
            }

            return result;
        }

        public static XYZ2SystemConfig Load(string name)
        {
            XYZ2SystemConfig config = XYZ2SystemConfig.Find(Criterion.Eq(TableXYZ2SystemConfig.ConfigName, name));
            return config;
        }
	}
}
